Suppose we want to draw a unary-binary tree T of height h having N nodes5. According to our internal representation, for each subtree in the stack we need
The following lemma relates to h and N the number of subtrees of T which are on the stack simultaneously and their heights.
(ht(T′) + 1) | ≤ | ht(Ts) + 1 + (ht(T′) + 1) | |
≤ | h + ≤. $$ |
Therefore, our implementation uses at most 9h + 2 min(N,(h + 1)(h + 2)/2) registers. In order to compare this with the 10N registers used in the straightforward implementation, an estimation of the average height of a tree with N nodes is needed. Several results, depending on the type of trees and of the randomization model, are cited in Figure , which compares the number of registers used in a straightforward implementation with the average number of registers used in our implementation. This table shows clearly the advantage of our implementation.